<!--
 @Author: libing/makeup1122
 @Email: makeup1123@163.com
 @Date: "2020-02-26 23:22:58"
-->
<template>
  <div>Callback
    <code>
      {{userinfo}}
    </code>
  </div>
</template>
<script>
export default {
  name: 'WxCallback',
  components: {},
  data: function () {
    return {
    }
  },
  created: function () {
    const code = window.location.href.match(/(?<=code=).*?(?=&)/g)
    const state = window.location.href.match(/(?<=&state=).*?(?=#\/callback)/g)
    if (code !== null && state !== null) {
      this.$store.dispatch('doLogin', code[0], state[0]).then(() => {
        const beforeRouterName = sessionStorage.getItem('beforeRouterName')
        if (beforeRouterName) {
          this.$router.push({ name: beforeRouterName })
        } else {
          this.$router.push({ name: 'Home' })
        }
      })
    }
  },
  computed: {
    userinfo: function() {
      return this.$store.state.member.userinfo
    }
  },
  methods: {}
}
</script>
<style scoped>
</style>
